#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>


/**
 * 
 * 混合图
 * 
 */
int main() {


	int n, m;
	scanf("%d %d", &n, &m);

	std::vector<std::vector<int>> graph(n, std::vector<int>());

	for (int i = 0; i < m; i++) {
		int a, x, y;
		scanf("%d %d %d", &a, &x, &y);
		if (a == 0) {
			graph[x].insert(graph[x].begin(), y);
		}
		else {
			graph[x].insert(graph[x].begin(), y);
			graph[y].insert(graph[y].begin(), x);
		}
	}

	for (int i = 0; i < n; i++) {
		printf("%d: ", i);
		for (int j = 0; j < graph[i].size(); j++) {
			printf("%d ", graph[i][j]);
		}
		printf("\n");
	}


}